local luoshen = fk.CreateSkill{
  name = "mod__luoshen",
}
local luoshen_ = {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local color = ""
    local pattern = ".|.|."
    while true do
      if color == "red" then
        pattern = ".|.|heart,diamond"
      elseif color == "black" then
        pattern = ".|.|spade,club"
      end
      local judge = {
        who = player,
        reason = self.name,
        pattern = pattern,
        skipdrop = true,
      }
      room:judge(judge)
      if color == "" then
        color = judge.card:getColorString()
      end
      if room:getCardArea(judge.card.id) == Card.DiscardPile and not player.dead then
        room:obtainCard(player.id, judge.card.id, true, fk.ReasonJustMove)
      end
      if judge.card:getColorString() ~= color or player.dead or not room:askForSkillInvoke(player, self.name) then
        break
      end
    end
  end,
}
local luoshen_obtain = {
  mute = true,
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.reason == "mod__luoshen" and player.room:getCardArea(data.card.id) == Card.Processing
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player, data.card, true, nil, player.id, "mod__luoshen", "@@mod__luoshen-inhand-turn")
  end,
}
local luoshen_maxcards = {
  exclude_from = function(self, player, card)
    return card:getMark("@@mod__luoshen-inhand-turn") > 0
  end,
}
luoshen:addEffect(fk.EventPhaseStart, luoshen_)
luoshen:addEffect(fk.FinishJudge, luoshen_obtain)
luoshen:addEffect("maxcards", luoshen_maxcards)
return luoshen